package com.dycx.api.controller.manage.cms;

import com.dycx.cms.dto.ArticleTypeDto;
import com.dycx.cms.service.ArticleTypeService;
import com.dycx.common.RestResponse;
import com.dycx.common.annotation.WriterLog;
import com.dycx.common.enums.BizTypeEnum;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;


@RestController
@RequestMapping(value = "/manage/cms/articleType")
public class ArticleTypeController {

    @Resource
    private ArticleTypeService articleTypeService;

    /**
     * 添加
     **/
    @WriterLog(bizType = BizTypeEnum.CMS_ARTICLE_TYPE, bizValue = "{#articleTypeDto.id}",logTitle = "添加文章分类" )
    @PostMapping("/add")
    public RestResponse<?> add(@RequestBody @Valid ArticleTypeDto articleTypeDto) {
        return articleTypeService.add(articleTypeDto) ? RestResponse.success() : RestResponse.fail();
    }

    /**
     * 修改
     **/
    @WriterLog(bizType = BizTypeEnum.CMS_ARTICLE_TYPE, bizValue = "{#articleTypeDto.id}",logTitle = "修改文章分类")
    @PostMapping("/edit")
    public RestResponse<?> edit(@RequestBody @Valid ArticleTypeDto articleTypeDto) {
        return articleTypeService.edit(articleTypeDto) ? RestResponse.success() : RestResponse.fail();
    }

    /**
     * 刪除
     **/
    @WriterLog(bizType = BizTypeEnum.CMS_ARTICLE_TYPE, bizValue = "{#typeId}",logTitle = "删除文章分类")
    @GetMapping("/delete")
    public RestResponse<?> delete(int typeId) {
        return articleTypeService.delete(typeId) ? RestResponse.success() : RestResponse.fail();
    }


    /**
     * 查询 根据主键 id 查询
     **/
    @GetMapping("/getAllList")
    public RestResponse<?> getAllList() {
        return RestResponse.success(articleTypeService.getAllList(0));
    }

    /**
     * 修改排序
     **/
    @WriterLog(bizType = BizTypeEnum.CMS_ARTICLE_TYPE, bizValue = "{#articleTypeDto.id}",logTitle = "排序文章分类")
    @PostMapping("/updateSort")
    public RestResponse<?> updateSort(@RequestBody ArticleTypeDto articleTypeDto) {
        return RestResponse.success(articleTypeService.updateSort(articleTypeDto));
    }

    /**
     * 修改状态
     **/
    @WriterLog(bizType = BizTypeEnum.CMS_ARTICLE_TYPE, bizValue = "{#articleTypeDto.id}",logTitle = "更新文章分类排序")
    @PostMapping("/updateStatus")
    public RestResponse<?> updateStatus(@RequestBody ArticleTypeDto articleTypeDto) {
        return RestResponse.success(articleTypeService.updateStatus(articleTypeDto));
    }

    /**
     * 查询子类
     **/
    @GetMapping("/getListByParentId")
    public RestResponse<?> getListByParentId(Integer parentId) {
        return RestResponse.success(articleTypeService.getListByParentId(parentId));
    }
}
